<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件化的基本使用</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
    <div id="app">
       
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
    </div>
    <template id="cpn1">
        <div>
            <h2>当前计数：{{counter}}</h2>
            <button @click="increment">+</button>
            <button @click="decrement">-</button>
        </div>
    </template>
    <script>
       
        Vue.component('cpn', {
            template: "#cpn1",
            data(){//数据存放在这里，组件中data是函数，返回一个对象
                return{
                   counter: 0
                }
            },
           methods: {
                increment() {
                    this.counter++
                },
                decrement() {
                    this.counter--
                }
            }
               
        })

        const app = new Vue({
            el: "#app",
            data: {
                
            }
          
        })
    </script>
</body>
</html>